<template>
  <div>
    <a-form :form="form" style="max-width: 500px; margin: 40px auto 0;" :label-col="labelCol" :wrapper-col="wrapperCol" >
      <a-form-model-item label="所学专业" aria-required="true">
        <j-tree-select
          :disabled="isdisabledF"
          placeholder=""
          dict="major,name,id"
          pidField="parentId"
          v-decorator="['professorMajor',{rules: [{ required: true, message: '请选择所学专业', trigger: 'blur' }]}]">
        </j-tree-select>
      </a-form-model-item>
      <a-form-item label="毕业院校" aria-required="true">
        <a-input :disabled="isdisabledF" v-decorator="['professorSchool',{rules: [{ required: true, message: '请填写毕业院校', trigger: 'blur' }]}]"></a-input>
      </a-form-item>

      <a-form-item  label="毕业时间" aria-required="true">
        <j-date :disabled="isdisabledF" v-decorator="['professorGraduateDate',{rules: [{ required: true, message: '请选择毕业时间', trigger: 'blur' }]}]" :trigger-change="true" style="width: 100%"/>
      </a-form-item>
      <a-form-item label="申报类别(请不要选择大类)" aria-required="true">
        <j-category-select
          :disabled="isdisabledF"
          placeholder=""
          v-decorator="['professorDeclareCategory',{ rules: [
        { required: true,message:'请不要选择大类',trigger:'blur'},
        { validator: checkPositiveInteger2 }]
}]"
          pcode="B03"
          multiple
        />
      </a-form-item>
      <a-form-item label="从事专业" aria-required="true">
        <a-input :disabled="isdisabledF" v-decorator="['professorWorkMajor',{ rules: [
        { required: true, message: '请填写从事专业',trigger:'blur'},
        { validator: checkPositiveInteger }]
}]"></a-input>
      </a-form-item>
      <a-form-item  label="从事专业时间" aria-required="true">
        <j-date :disabled="isdisabledF" v-decorator="['professorMajorDate',{rules: [{ required: true, message: '请选择从事专业时间', trigger: 'blur' }]}]" :trigger-change="true" style="width: 100%"/>
      </a-form-item>
      <a-form-item  label="参加工作时间" aria-required="true">
        <j-date  :disabled="isdisabledF" v-decorator="['professorBeginWork',{rules: [{ required: true, message: '请选择参加工作时间', trigger: 'blur' }]}]" :trigger-change="true" style="width: 100%"/>
      </a-form-item>
      <a-form-item label="工作单位"   aria-required="true">
        <a-input :disabled="isdisabledF" v-decorator="['professorWorkUnit',{rules: [{ required: true, message: '请填写工作单位', trigger: 'blur' }]}]"></a-input>
      </a-form-item>
      <a-form-item  label="职务" aria-required="true">
        <a-input :disabled="isdisabledF" v-decorator="['professorPosition',{rules: [{ required: true, message: '请填写职务', trigger: 'blur' }]}]"></a-input>
      </a-form-item>
      <a-form-item  label="技术职称" aria-required="true">
        <j-dict-select-tag :disabled="isdisabledF" type="list" v-decorator="['professorTitle',{rules: [{ required: true, message: '请选择技术职称', trigger: 'blur' }]}]" :trigger-change="true" dictCode="job_title"/>
      </a-form-item>


      <a-form-item label="本人支持或参加过的典型项目" aria-required="true">
        <a-textarea :disabled="isdisabledF" :rows="4" v-decorator="['professorProjectIntroduce',{rules: [{ required: true, message: '请填写支持或参加过的项目', trigger: 'blur'}]}]" placeholder="(包括项目名称、建设规模、投资额及所负责的内容)"/>
      </a-form-item>

      <a-form-item label="业务主管部门意见">
        <a-textarea :rows="4" v-decorator="['professorLeadMsg']" disabled/>
      </a-form-item>
      <a-form-item label="行政审批局意见" >
        <a-textarea :rows="4" v-decorator="['professorApproveMsg']" disabled/>
      </a-form-item>

      <a-form-item :wrapperCol="{span: 19, offset: 5}">
        <a-button type="primary" style="float: left;margin-top: 5px" @click="prevStep">上一步</a-button>
        <a-button  v-if="!isdisabledF" type="primary"  style="float: left;margin-left: 5px;margin-top: 5px" @click="SaveTemp">点击保存</a-button>
        <div>
          <a-button  type="primary" style="float: left;margin-left: 5px;margin-top: 5px;margin-right:5px"  @click="exportPDF">下载文件</a-button>
          <a-modal okText="预览我的PDF" :visible="geturl.show" title="温馨提示" @ok="handleOkkk1" @cancel="handleOkkk">
            <p>由于IOS系统不允许跳转浏览器下载文件，麻烦您将下面的链接复制张贴到浏览器下载pdf文件</p>
            <p>{{geturl.url}}</p>
          </a-modal>
        </div>
        <a-button  type="primary" style="float: left;margin-top: 5px" @click="nextStep01">下一步</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script>
import JDate from '@/components/jeecg/JDate'
import JCategorySelect from '@/components/jeecg/JCategorySelect'
import JTreeSelect from '@/components/jeecg/JTreeSelect'
import JAreaLinkage from '@comp/jeecg/JAreaLinkage'
import ATextarea from "ant-design-vue/es/input/TextArea";
import {downloadFile} from '@/api/manage'
import {getAction} from '@/api/manage'
// 导入
import JImageUpload from '@/components/jeecg/JImageUpload'
import ACol from "ant-design-vue/es/grid/Col";
export default {
  name: "Step2",
  components:{
    ACol,
    ATextarea,
    JAreaLinkage,
    JImageUpload,
    JCategorySelect,
    JDate,
    JTreeSelect,
    downloadFile
  },
  props:{
    status:{
      default:'',
      type: String
    },
    geturl:{
      default:{
        url:'',
        show:false,
      },
      type:Object,
    },
    tes:{
      default:{},
      type: Object
    },
    isdisabledF:{
      default:0,
      type: Boolean
    }
  },
  created(){
  },
  mounted(){
    this.form.setFieldsValue({
      professorSchool:this.tes.professorSchool,
      professorMajor:this.tes.professorMajor,
      professorGraduateDate:this.tes.professorGraduateDate,
      professorWorkUnit:this.tes.professorWorkUnit,
      professorDeclareCategory:this.tes.professorDeclareCategory,
      professorPosition:this.tes.professorPosition,
      professorBeginWork:this.tes.professorBeginWork,
      professorTitle:this.tes.professorTitle,
      professorWorkMajor:this.tes.professorWorkMajor,
      professorMajorDate:this.tes.professorMajorDate,
      professorProjectIntroduce:this.tes.professorProjectIntroduce,
      professorLeadMsg:this.tes.professorLeadMsg,
      professorApproveMsg:this.tes.professorApproveMsg,
    });
  },
  data () {
    return {
      text:"下载文件",
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      loading: false,
      form:this.$form.createForm(this),
      marjorId:"",
      schoolId:"",
      fieldvalue:{
        professorMajor:'',
        professorSchool:'',
        professorGraduateDate:'',
        professorDeclareCategory:'',
        professorWorkMajor:'',
        professorMajorDate:'',
        professorBeginWork:'',
        professorWorkUnit:'',
        professorPosition:'',
        professorTitle:'',
        professorProjectIntroduce:'',
      },
    }
  },
  methods: {
    handleOkkk1(e){
      console.log(e);
      this.geturl.show=false;
      let a = document.createElement('a') //创建a标签
      a.href = this.geturl.url
      a.click()
    },
    handleOkkk(e){
      console.log(e);
      this.geturl.show=false;
    },
    SaveTemp(){
      this.getfieldvalue();
      if((Object.keys(this.fieldvalue).filter(v=>!this.fieldvalue[v]).length<=0)){
        if(this.fieldvalue.professorDeclareCategory!=null){
          let url = "/sys/category/findById?ids=" +this.fieldvalue.professorDeclareCategory;
          getAction(url).then((res)=>{
            console.log(res);
            if(res.success){
              if (res.result == 0){
                this.$emit('setfiled1',this.fieldvalue);
                this.$emit('saveTemp');
              }else {
                this.$message.error('申报类型请勿选择大类')
              }
            }
          })
        }
      }else{
        this.$message.error("请仔细检查是否有未填写项！")
      }
    },
    exportPDF(){
      this.SaveTemp();
      this.getfieldvalue();
      if((Object.keys(this.fieldvalue).filter(v=>!this.fieldvalue[v]).length<=0)){
        if(this.fieldvalue.professorDeclareCategory!=null){
          let url = "/sys/category/findById?ids=" +this.fieldvalue.professorDeclareCategory;
          getAction(url).then((res)=>{
            console.log(res);
            if(res.success){
              if (res.result == 0){
                this.$emit('setfiled1',this.fieldvalue);
                this.$emit('ExportPDF');
              }else {
                this.$message.error('申报类型请勿选择大类')
              }
            }
          })
        }
      }else{
        this.$message.error("请仔细检查是否有未填写项！")
      }
    },
    getfieldvalue(){
      const that = this;
      this.form.validateFields((err, values) => {
        // 获取表单中type的id
        this.fieldvalue.professorMajor = that.form.getFieldValue("professorMajor") ;
        this.fieldvalue.professorSchool = that.form.getFieldValue("professorSchool");
        this.fieldvalue.professorGraduateDate = that.form.getFieldValue("professorGraduateDate");
        this.fieldvalue.professorDeclareCategory = that.form.getFieldValue("professorDeclareCategory");
        this.fieldvalue.professorWorkMajor = that.form.getFieldValue("professorWorkMajor");
        this.fieldvalue.professorMajorDate = that.form.getFieldValue("professorMajorDate");
        this.fieldvalue.professorBeginWork = that.form.getFieldValue("professorBeginWork");
        this.fieldvalue.professorWorkUnit = that.form.getFieldValue("professorWorkUnit");
        this.fieldvalue.professorPosition = that.form.getFieldValue("professorPosition");
        this.fieldvalue.professorTitle = that.form.getFieldValue("professorTitle");
        this.fieldvalue.professorProjectIntroduce = that.form.getFieldValue("professorProjectIntroduce");
      })
    },
    nextStep01 () {
      this.getfieldvalue();
      if((Object.keys(this.fieldvalue).filter(v=>!this.fieldvalue[v]).length<=0)){
        if(this.fieldvalue.professorDeclareCategory!=null){
          let url = "/sys/category/findById?ids=" +this.fieldvalue.professorDeclareCategory;
          getAction(url).then((res)=>{
            console.log(res);
            if(res.success){
              if (res.result == 0){
                this.$emit('nextStep');
                this.$emit('setfiled1',this.fieldvalue);
              }else {
                this.$message.error('申报类型请勿选择大类')
              }
            }
          })
        }
      }else{
          this.$message.error("请仔细检查是否有未填写项！")
      }
    },
    checkPositiveInteger(rule, value, callback){
      console.log(value)
      const size = Array.from(value).length;
      console.log(size)
      if ( size<=15) {
        // 如果需要返回 error msg，就把它传给 `callback()`
        callback();
      }
      else {
        // 如果通过校验，调用无参数的 `callback()` 即可
        callback('请输入小于15个字的从事专业');
      }
    },
    checkPositiveInteger2(rule, value, callback){
      const array = value.split(",");
      console.log(value)
      const size = Array.from(array).length;
      console.log(size)
      if ( size<=5) {
        // 如果需要返回 error msg，就把它传给 `callback()`
        callback();
      }
      else {
        // 如果通过校验，调用无参数的 `callback()` 即可
        callback('请选择5个以内的申报类别');
      }
    },
    prevStep () {
      this.getfieldvalue();
      this.$emit('prevStep')
      this.$emit('setfiled1',this.fieldvalue);
    }
  }
}
</script>

<style lang="less" scoped>
.stepFormText {
  margin-bottom: 24px;

  .ant-form-item-label,
  .ant-form-item-control {
    line-height: 22px;
  }
}
</style>